package com.cnap.multiclouldmgmt.scheduleTask;

import com.cnap.multiclouldmgmt.MulticlouldmgmtApplicationTests;
import com.cnap.multiclouldmgmt.model.enums.CreateVmStepEnum;
import com.cnap.multiclouldmgmt.model.vm.VmCreateModel;
import com.cnap.multiclouldmgmt.repository.master.VmCreateInfoMapper;
import com.cnap.multiclouldmgmt.service.CacheService;
import com.cnap.multiclouldmgmt.service.VmResourceService;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;

import java.util.ArrayList;
import java.util.List;

class CreateVmScheduledTaskTest extends MulticlouldmgmtApplicationTests {

    @MockBean
    private VmCreateInfoMapper vmCreateInfoMapper;

    @MockBean
    private VmResourceService vmResourceService;

    @MockBean
    private CacheService cacheService;

    @Autowired
    private CreateVmScheduledTask createVmScheduledTask;

    @Test
    void createVmInfo() {

        List<VmCreateModel> vmCreateModels = new ArrayList<>();
        VmCreateModel vmCreateModel01 = new VmCreateModel();
        vmCreateModel01.setSvcId("01");
        VmCreateModel vmCreateModel02 = new VmCreateModel();
        vmCreateModel02.setSvcId("02");
        VmCreateModel vmCreateModel03 = new VmCreateModel();
        vmCreateModel03.setSvcId("03");
        vmCreateModel03.setErrorMsg("ss");
        VmCreateModel vmCreateModel04 = new VmCreateModel();
        vmCreateModel04.setType(CreateVmStepEnum.End.getDescribe());
        vmCreateModel04.setSvcId("04abcdefa2022202220202020202020202020202020202020202020202");

        vmCreateModels.add(vmCreateModel01);
        vmCreateModels.add(vmCreateModel02);
        vmCreateModels.add(vmCreateModel03);
        vmCreateModels.add(vmCreateModel04);
        
        Mockito.when(vmCreateInfoMapper.getAllCreateInfo()).thenReturn(vmCreateModels);
        Mockito.when(cacheService.getVmCreateTime("01")).thenReturn(1L);
        Mockito.when(cacheService.getVmCreateTime("02")).thenReturn(-1L);

        createVmScheduledTask.createVmInfo();

    }
}